package com.wno704.intf.service.impl;

import com.wno704.intf.config.WnoConfig;
import com.wno704.intf.entity.IntfLog;
import com.wno704.intf.service.IntfLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

/**
 * @ClassName IntfLogServiceImpl
 * @Description TODO
 * @Author wno704
 * @Date 2023/10/24 9:21
 * @Version 1.0
 */
@Slf4j
@Service("intfLogService")
public class IntfLogServiceImpl implements IntfLogService {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Autowired
    WnoConfig wnoConfig;

    @Override
    public int insertLog(IntfLog intfLog) {
        String upSql = "INSERT INTO " + wnoConfig.getTablePrefix() + "LOG (LOG_ID ,INTF_ID ,METHOD ,URL ,REMARK ,REQUEST_IPADDR ,REQUEST_HEADERS ,REQUEST_PARAM ,REQUEST_MSG ,REQUEST_TIME ) VALUES (?,?,?,?,?,?,?,?,?,?)";
        return this.jdbcTemplate.update(upSql, new Object[]{intfLog.getLogId(),
            intfLog.getIntfId(),intfLog.getMethod(),intfLog.getUrl(),intfLog.getRemark(),
            intfLog.getRequestIpAddr(),intfLog.getRequestHeaders(),intfLog.getRequestParam(),intfLog.getRequestMsg(),intfLog.getRequestTime()});
    }

    @Override
    public int updateLog(IntfLog intfLog) {
        String upSql = "UPDATE " + wnoConfig.getTablePrefix() + "LOG  SET RESPONSE_TIME = ?, RESPONSE_MSG = ?, RESPONSE_STATUS=?, RESPONSE_HEADERS=? WHERE LOG_ID = ? ";
        return this.jdbcTemplate.update(upSql, new Object[]{intfLog.getResponseTime(),intfLog.getResponseMsg(),intfLog.getResponseStatus(),intfLog.getResponseHeaders(),intfLog.getLogId()});
    }
}
